Skip to content

fix: answer range format validation and error message in Numerical input#2426

Merged
bradenmacdonald merged 5 commits intoopenedx:masterfrom
raccoongang:romaniuk/answer-range-validation
Oct 15, 2025
Merged

fix: answer range format validation and error message in Numerical input#2426
bradenmacdonald merged 5 commits intoopenedx:masterfrom
raccoongang:romaniuk/answer-range-validation

Conversation

@ihor-romaniuk
Copy link
Contributor

@ihor-romaniuk ihor-romaniuk commented Sep 5, 2025

Backport Pull Requests to frontend-lib-content-components: openedx-unsupported/frontend-lib-content-components#511

Description

These fixes enhance input range validation for numeric responses in OLX format.

The updated logic ensures that user responses follow a consistent, predictable format and that all invalid or ambiguous cases are correctly rejected.


Supported response formats

  • Inclusive or exclusive bounds:
    • [1,10], (1,10), [-5,10], (-1.5,7.25)
  • Optional whitespace:
    • [1, 10], [ 1,10 ], [ 1 , 10 ], ( -1 , 1 )
  • Decimal and negative values:
    • [1.1,10.5], [-2.5,5]
  • Fractional values:
    • [1/2,2], (1/4,3/4), [-3/2,-1/2]

Invalid response examples

  • Mismatched or missing brackets:
    • {1,10}, (1,10], [1,10
  • Missing comma or spacing issues:
    • [1 10], (1,,10)
  • Missing bounds:
    • (,10), (1,), []
  • Invalid numeric formats:
    • [1;10], [1.10], [--5,10], [1/10]
  • Incorrect range order:
    • [10,1] (min > max)

Steps to reproduce

  1. Go to studio -> unit -> problem -> Numerical input
  2. In answers click on Add answer button -> Add answer range
  3. Fill in value [5.8), click Save (like user set dot instead of comma by mistake)

Actual result

Nothing happened, in console there's error
000
Note: the same when user print additional bracket

Expected result

Some validation should be for field or some error message for user should be shown
Before save:
0001
After save:
0002

Note

Old closed MR #1557

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 5, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @ihor-romaniuk!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the core contributor PR author is a Core Contributor (who may or may not have write access to this repo). label Sep 5, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Sep 5, 2025
@codecov
Copy link

codecov bot commented Sep 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.75%. Comparing base (1d6fdc3) to head (b256194).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2426      +/-   ##
==========================================
+ Coverage   94.71%   94.75%   +0.04%     
==========================================
  Files        1202     1205       +3     
  Lines       26845    26950     +105     
  Branches     6023     5896     -127     
==========================================
+ Hits        25425    25536     +111     
- Misses       1350     1355       +5     
+ Partials       70       59      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

}
if (rawUpperBound.includes('/')) {
if (!rawUpperBound) {
upperBoundInt = lowerBoundInt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, just adding context to the failing codecov check.

It seems codecov isn't considering this line as covered

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for notice, I have removed this line because it is no longer needed.

@bradenmacdonald
Copy link
Contributor

I think there is a bug with negative numbers. Negative numbers should be allowed, but it's showing them as an error:

Screenshot 2025-09-16 at 10 35 21 AM

@mphilbrick211 mphilbrick211 moved this from Ready for Review to In Eng Review in Contributions Sep 26, 2025
@ihor-romaniuk ihor-romaniuk force-pushed the romaniuk/answer-range-validation branch from cf8e336 to 9792794 Compare October 14, 2025 20:16
@ihor-romaniuk
Copy link
Contributor Author

@bradenmacdonald Thanks for your check. I have extended a regexp to allow negative numbers.

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is one more issue?

const [numerator, denominator] = lowerBoundFraction.split('/');
const lowerBoundFloat = Number(numerator) / Number(denominator);
lowerBoundInt = lowerBoundFloat;
lowerBoundInt = Number(numerator) / Number(denominator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! What about these fractional values like [1/2,3/4] ? They seem to be supported in the code, and on master they are working, but with this PR it rejects them as invalid.

Screenshot 2025-10-14 at 5 35 51 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks. Also add support for fractions numbers.

@bradenmacdonald
Copy link
Contributor

There is another bug, but I think it's out of scope here:

  1. Edit a numerical input problem and give a "answer range" of [-1/2,8/4). Save changes.
    Screenshot 2025-10-15 at 11 28 43 AM
  2. Edit the same problem. The answer is no longer in "answer range" mode with validation, and is now listed as a regular answer. It still works fine, however.
    Screenshot 2025-10-15 at 11 28 15 AM

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks!

If you'd like to submit another PR for the other bug ^ , I'll try to review+merge it quickly.

@bradenmacdonald bradenmacdonald merged commit 4a26a86 into openedx:master Oct 15, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from In Eng Review to Done in Contributions Oct 15, 2025
@ihor-romaniuk ihor-romaniuk deleted the romaniuk/answer-range-validation branch October 19, 2025 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants